<?php

class Category_Model extends CI_Model {

    //put your code here
    function __construct() {
        parent::__construct();
    }

    function GetTopCategory() {
        $query = $this->db->get_where(MYSQL_TABLE_PREFLIX.TABLE_CATEGORY, array('ParentID' => null));
        return $query->result_array();
    }

    function GetChildCategory($id) {
        $query = $this->db->get_where(MYSQL_TABLE_PREFLIX.TABLE_CATEGORY, array('ParentID' => $id));
        return $query->result_array();
    }
    
    function Get($data){
        $query = $this->db->get_where(MYSQL_TABLE_PREFLIX.TABLE_CATEGORY, $data);
        return $query->result_array();
    }
    
    function GetAllCategory() {
        $parents = $this->GetTopCategory();
        $data = array();
        foreach($parents as $parent){
            $parent['Childs'] = array();
            $parent['Childs'] = $this->GetChildCategory($parent['CategoryID']);
            $data[] = $parent;
        }
        return $data;
    }

}
